from flask_restful.reqparse import RequestParser
from flask_restful import Resource
from comment.modules.funding_not_matched import Funding_not_matched
from financial.resource.transaction.serializers import AllMatchedPaginateSerializer

class AllMatchedResource(Resource):
     """所有带匹配资金列表 和 所有已经匹配资金列表"""
     def get(self):
         rq = RequestParser()

         rq.add_argument('curPage')  # 当前页
         rq.add_argument('perPage')  # 每页数量
         rq.add_argument('type')  # 匹配状态,如果传入的2 ，则查询所有的已经匹配列表，未匹配不用传

         args = rq.parse_args()

         cur_page = int(args.get('curPage'))
         per_page = int(args.get('perPage'))
         status = args.get('type')

         if not status:
             # 查询所有未匹配和部分匹配的
             matched_list = Funding_not_matched.query.filter(Funding_not_matched.matchedStatus != 2)
         else:
             matched_list = Funding_not_matched.query.filter(Funding_not_matched.matchedStatus == 2)
         matched_list = matched_list.paginate(cur_page , per_page ,error_out=False)

         data = AllMatchedPaginateSerializer(matched_list).to_dict()
         return {'msg':'success','data':data}